package com.ruoyi.web.controller.zzwt;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.zzw.LongListDto;
import com.ruoyi.common.core.domain.zzw.TEventTrack;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.service.ITEventTrackService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 关联事件Controller
 * 
 * @author xbx
 * @date 2023-10-20
 */
@RestController
@RequestMapping("/system/event/track")
public class TEventTrackController extends BaseController
{
    @Autowired
    private ITEventTrackService tEventTrackService;

    /**
     * 查询关联事件列表
     */
    @PreAuthorize("@ss.hasPermi('system:track:list')")
    @GetMapping("/list")
    public TableDataInfo list(TEventTrack tEventTrack)
    {
        startPage();
        List<TEventTrack> list = tEventTrackService.selectTEventTrackList(tEventTrack);
        return getDataTable(list);
    }

    /**
     * 导出关联事件列表
     */
    @PreAuthorize("@ss.hasPermi('system:track:export')")
    @Log(title = "关联事件", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TEventTrack tEventTrack)
    {
        List<TEventTrack> list = tEventTrackService.selectTEventTrackList(tEventTrack);
        ExcelUtil<TEventTrack> util = new ExcelUtil<TEventTrack>(TEventTrack.class);
        util.exportExcel(response, list, "关联事件数据");
    }

    /**
     * 获取关联事件详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:track:query')")
    @GetMapping(value = "/{cId}")
    public AjaxResult getInfo(@PathVariable("cId") Long cId)
    {
        return success(tEventTrackService.selectTEventTrackByCId(cId));
    }

    /**
     * 新增关联事件
     */
    @PreAuthorize("@ss.hasPermi('system:track:add')")
    @Log(title = "关联事件", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody TEventTrack tEventTrack)
    {
        return toAjax(tEventTrackService.insertTEventTrack(tEventTrack));
    }

    /**
     * 修改关联事件
     */
    @PreAuthorize("@ss.hasPermi('system:track:edit')")
    @Log(title = "关联事件", businessType = BusinessType.UPDATE)
    @PutMapping("update")
    public AjaxResult edit(@RequestBody TEventTrack tEventTrack)
    {
        return toAjax(tEventTrackService.updateTEventTrack(tEventTrack));
    }

    /**
     * 删除关联事件
     */
    @PreAuthorize("@ss.hasPermi('system:track:remove')")
    @Log(title = "关联事件", businessType = BusinessType.DELETE)
	@DeleteMapping("/batchDelete")
    public AjaxResult remove(@RequestBody LongListDto dto)
    {
        return toAjax(tEventTrackService.deleteTEventTrackByCIds(dto.getIds()));
    }
}
